package cn.waka.sys.admin.dao;

import java.util.List;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import cn.waka.sys.admin.object.ResourceData;

@Mapper
public interface ResourceDataDao {

    int save(ResourceData rd);

    List<ResourceData> findPage(@Param("resourceId") int resourceId, @Param("start") int start, @Param("size") int size);

    int findTotal(@Param("resourceId") int resourceId);

    ResourceData findById(@Param("id") int id);

    @Update("update s_resource_data set title=#{title},url=#{url},img=#{img},length=#{length} where id=#{id}")
    int update(ResourceData rd);

    @Select("SELECT MAX(sort) FROM `s_resource_data` WHERE resource_id=#{resourceId} and is_del=0")
    Object maxSort(int resourceId);

    @Update("update s_resource_data set sort=#{sort} where id=#{id}")
    int sort(@Param("id") int id, @Param("sort") int sort);

    @Update("update s_resource_data set sort=sort-1 where resource_id=#{resourceId} and sort>#{sort} and is_del=0")
    int top_dec(@Param("resourceId") int resourceId, @Param("sort") int sort);

    @Update("update s_resource_data set sort=sort-1 where resource_id=#{resourceId} and sort=#{sort} and is_del=0")
    int up_dec(@Param("resourceId") int resourceId, @Param("sort") int sort);

    @Update("update s_resource_data set sort=sort+1 where resource_id=#{resourceId} and sort=#{sort} and is_del=0")
    int down_inc(@Param("resourceId") int resourceId, @Param("sort") int sort);
}
